package com.kxxnzstdsw.plugins

import com.zaxxer.hikari.HikariDataSource
import io.ktor.server.application.*
import io.lettuce.core.api.StatefulRedisConnection
import org.koin.ktor.ext.inject

fun Application.clientConfig() {
  initDatabase()
  initRedis()
}

private fun Application.initDatabase() {
  val dataSource by inject<HikariDataSource>()
  dataSource.connection.use { con ->
    con.prepareStatement("select 1;").executeQuery().let { resultSet ->
      while (resultSet.next()) {
        log.info("数据库连接成功")
      }
    }
  }
}

private fun Application.initRedis() {
  val connection by inject<StatefulRedisConnection<String, String>>()
  connection.async().get("1")
  log.info("redis连接成功")
}
